package cn.wolfcode.service.impl;
import cn.wolfcode.domain.Business;
import cn.wolfcode.domain.SystemDictionary;
import cn.wolfcode.mapper.BusinessMapper;
import cn.wolfcode.qo.BusinessQueryObject;
import cn.wolfcode.service.IBusinessService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class BusinessServiceImpl implements IBusinessService {

    @Autowired
    private BusinessMapper businessMapper;

    @Override
    @Transactional
    public void save(Business business) {
        //调mapper接口中的方法
        businessMapper.insert(business);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        businessMapper.deleteByPrimaryKey(id);
    }

    @Override
    @Transactional
    public void update(Business business) {
        businessMapper.updateByPrimaryKey(business);
    }

    @Override
    public Business get(Long id) {
        return businessMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Business> listAll() {
        return businessMapper.selectAll();
    }

    @Override
    public PageInfo<Business> query(BusinessQueryObject qo) {
        //定义查询页,每页页数
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),"open_date desc");
        List<Business> list = businessMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    @Override
    public Business queryMainStore() {
        return businessMapper.selectMainStore();
    }


}
